#!/usr/bin/expect
#如果时间超时没有屏幕输出，会直接运行下面的代码，默认10s太危险，不再设置超时
set timeout -1

set ip "210.30.100.4"
set user "user"
set password "OurEDALectureServer"
set remoteCmd "./git_pull.sh"

spawn ssh $user@$ip
expect {
 "*yes/no" { send "yes\r"; exp_continue}
 "*password:" { send "$password\r"}
}
expect "*$*"
send "cd /home/user/www/IMooc/ \r"
expect "*$*"
send "$remoteCmd\r"
expect "*$*"
send "sudo su\r"
expect "*password for *"
send "$password\r"
expect "*#*"
send "supervisorctl restart IMooc\r"
interact

#send "/sbin/ifconfig -a | grep inet |grep -v 127.0.0.1 |grep -v inet6 | awk '{print \$2}' | tr -d \"地址:\"\"addr:\" \r"
#expect -re ".*"
#if {$expect_out(0,string)!="210.30.100.4"} {
#
#}else{
#
#}
